package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.SettingsVo;
import com.tanhua.domain.vo.UserInfoVoAge;
import com.tanhua.server.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import sun.net.www.ParseUtil;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingController {
    @Autowired
    private SettingService settingService;

    @GetMapping("/settings")
    public ResponseEntity querySettings() {
        SettingsVo vo = settingService.querySettings();
        return ResponseEntity.ok(vo);
    }

    @PostMapping("/notifications/setting")
    public ResponseEntity SetSettings(@RequestBody SettingsVo vo) {
        settingService.SetSettings(vo);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(value = "page", defaultValue = "1") Long page,
                                    @RequestParam(value = "pagesize", defaultValue = "10") Long pagesize) {
        page = page > 0 ? page : 1;
        pagesize=pagesize>10?page:10;
        //限制最大查询页数
        pagesize=pagesize>50?page:50;
     PageResult<UserInfoVoAge> pageResult= settingService.blackListPage(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
    /**
     * 保存陌生人问题
     * @param paramMap
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity updateQuestion(@RequestBody Map<String,String> paramMap) {
        settingService.updateQuestion(paramMap);
        return ResponseEntity.ok(null);
    }
    /**
     * 移除黑名单
     * @param blackUserId
     * @return
     */
    @DeleteMapping("/blacklist/{blackUserId}")
    public ResponseEntity removeBlackList(@PathVariable Long blackUserId){
        settingService.removeBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }
}
